class VueTest {
  constructor () {
    this._event = {}
  }
  $on (event, callback) {
    (this._event[event] = []).push(callback)
    return this
  }
  $off (event) {
    this._event[event] = []
    return this
  }
  $once (event, callback) {
    const on = () => {
      this.$off(event)
      callback.apply(this, arguments)
    }
    this.$on(event, on)
    return this
  }
  $emit (event) {
    for (let v of this._event[event].values()) {
      v(arguments)
    }
  }
}
const v = new VueTest()
v.$on('lee', () => {
  console.log('i am a lee')
})
v.$emit('lee') // i am a lee
v.$off('lee')
// v.$emit('lee') 报错
v.$once('lee2', () => {
  console.log('i am a lee2')
})
v.$emit('lee2') // i am a lee2
v.$emit('lee2') // 没打印